package com.iweb.utils;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

public class DataUtil{

    // 参数的解析
    public static  <T> T data(HttpServletRequest request,Class clazz){
        // 从 request 对象中获取所有的请求参数
        Enumeration<String> names = request.getParameterNames();
        Map<String,String> map = new HashMap<>();
        while (names.hasMoreElements()){
            String key = names.nextElement();
            map.put(key,request.getParameter(key));
        }
        String jsonStr = JSON.toJSONString(map);
        return (T) JSON.parseObject(jsonStr,clazz);
    }

}
